package com.dubbo.regulate.service;
import java.util.Date;

import com.alibaba.dubbo.config.annotation.Service;
import com.dubbo.common.dtos.PageResponseResult;
import com.dubbo.common.dtos.ResponseResult;
import com.dubbo.model.balance.dtos.PageRequestDto;
import com.dubbo.model.regulate.dtos.AddrManagementDto;
import com.dubbo.model.regulate.pojos.RegManagement;
import com.dubbo.regulate.mapper.AddClassMapper;
import com.dubbo.regulate.mapper.RegulateMapper;
import com.dubbo.regulate.regulateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Service
@Component
public class CarRegulateService implements regulateService {

    @Autowired
    private RegulateMapper regulateMapper;

    @Autowired
    private AddClassMapper addClassMapper;

    @Override
    public ResponseResult<List<RegManagement>> parentsRegulateList(PageRequestDto dto) {

        //设置页码大小
        dto.checkParam();
        Integer dtoPage = dto.getPage();
        dto.setPage((dtoPage - 1) * dto.getSize());

        Integer count = regulateMapper.count(); //查询总页码数
        List<RegManagement> manageList = regulateMapper.parentsManageList(dto);

        PageResponseResult pageResponseResult = new PageResponseResult(dtoPage,dto.getSize(),count);
        pageResponseResult.setData(manageList);

        return pageResponseResult;
        //return null;
    }

    /*
    * 新增服务项目类
    * */
    @Override
    public ResponseResult AddServiceClass(AddrManagementDto managementDto) {

        RegManagement regManagement = new RegManagement();
        regManagement.setsManageId(managementDto.getSManageId());
        regManagement.setsItem(managementDto.getSItem());
        regManagement.setsCreatetime(new Date());

        addClassMapper.AddClass(regManagement);
        return null;
    }

    /*
     * 修改服务项目类
     * */
    @Override
    public ResponseResult UpdateServiceClass(AddrManagementDto managementDto) {
        RegManagement regManagement = new RegManagement();
        regManagement.setsManageId(managementDto.getSManageId());
        regManagement.setsItem(managementDto.getSItem());
        regManagement.setsCreatetime(new Date());

        addClassMapper.UpdateCatalog(regManagement);
        return null;
    }

    //测试
    @Override
    public ResponseResult<String> test() {

        return ResponseResult.okResult(200,"ok");
    }
}
